﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Xml.Serialization;

namespace FisheryPlatform.SiteConfig
{
    [Serializable]
    [XmlRoot(ElementName = "AppSettings")]
    public class AppSettingsCollection : CollectionBase
    {
        //public string this[int index]
        //{
        //    get { return ((AppSetting)this.List[index]).Value; }
        //}

        //public string this[string key]
        //{
        //    get
        //    {
        //        return Get(key).Value;
        //    }
        //}

        public AppSetting this[int index]
        {
            get { return ((AppSetting)this.List[index]); }
        }

        public AppSetting this[string key]
        {
            get
            {
                return Get(key);
            }
        }

        public void Add(AppSetting item)
        {
            this.List.Add(item);
        }

        public AppSetting Get(string key)
        {
            foreach (AppSetting item in this.List)
            {
                if (string.Compare(item.Key, key, true) == 0)
                {
                    return item;
                }
            }
            return new AppSetting();
        }

        public string GetValue(string key)
        {
            var item = Get(key);
            if (item != null)
            {
                return item.Value;
            }
            return "";
        }

        public List<string> GetValues()
        {
            var result = new List<string>();
            foreach (AppSetting item in this.List)
            {
                result.Add(item.Value);
            }
            return result;
        }

        public List<string> GetKeys()
        {
            var result = new List<string>();
            foreach (AppSetting item in this.List)
            {
                result.Add(item.Key);
            }
            return result;
        }
    }
}
